<?php

namespace app\admin\model;
use fast\Tree;
use think\Model;

class School extends Model
{

    // 表名
    protected $name = 'school';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    // 追加属性
    protected $append = [
        'status_text'
    ];

    public function getStatusList()
    {
        return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
    }

    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : $data['status'];
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }
	
	public static function getTreeList($selected = [])
    {
        
		
		
		
		$ruleList = collection(self::where('status', 'normal')->order('id asc')->select())->toArray();
		
		$total = count($ruleList);
		
        //Tree::instance()->init($ruleList);
		
        //$ruleli = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'name');
		//print_r($ruleli);die;
		
		$nodeList = [];
       // Tree::instance()->init($ruleList);

		
		foreach ($ruleList as $k => $v) {
            $nodeList[$k]['id'] = $v['name'];
			$nodeList[$k]['schoolname'] = $v['name'];
        }
		
		//$list[0] = $nodeList;
		



		$result = array("list" => $nodeList,"total" => $total );

		return json($result);
		
		
    }

}
